package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.TFrontInformation;
import model.TFrontInformationType;
import model.VBackAdminUser;
import model.VCloudInformation;
import model.VFrontInformation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import annotation.Log;
import persistent.factory.DAOFactory;
import util.toolkit.Constant;
import util.toolkit.Expression;
import util.toolkit.ResponseJSON;
import util.toolkit.TimeUtil;

/**
 * 信息处理控制类
 * @author 徐震霖
 * @since 2018-12-13 10:24
 */
@Controller
@RequestMapping(value="/informationmanagement")
public class SysInformationManagementController {

	/**
	 * 类型信息添加处理类
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 类型信息添加处理类
	@Log(operationType = Constant.OPERTATION_ADD, operationDescribe = "添加一个类型信息", 
			operationClassPath = "controller.SysTitleManagementController.savestuList(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/addinfotype")
	public String addInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String typeName = req.getParameter("typename");
			String describe = req.getParameter("describe");
			if (typeName != null && !typeName.equals("") && describe != null && !describe.equals("")) {
				TFrontInformationType infotype = new TFrontInformationType();
				infotype.setIsdelete(true);
				infotype.setTypename(typeName);
				infotype.setDescribe(describe);
				int row = DAOFactory.getFrontInformationTypeDAO().addInfoType(infotype);
				if(row > 0){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "类型信息添加成功！");
				}
				else {
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "出现错误，类型信息添加失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "必填项不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现错误，类型信息添加失败，请重试！");
			e.printStackTrace();
		}
				
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 类型信息修改处理类
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 类型信息修改处理类
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "修改一个类型信息", 
			operationClassPath = "controller.SysTitleManagementController.updateInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/updateinfotype")
	public String updateInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String typeName = req.getParameter("typename");
			String describe = req.getParameter("describe");
			String typeid = req.getParameter("typeid");
			if (typeName != null && !typeName.equals("") && describe != null && !describe.equals("") 
					&& typeid != null && !typeid.equals("") && !typeid.equals("0")) {
				TFrontInformationType infotype = new TFrontInformationType();
				infotype.setIsdelete(true);
				infotype.setTypename(typeName);
				infotype.setDescribe(describe);
				infotype.setTypeid(Integer.parseInt(typeid));
				if(DAOFactory.getFrontInformationTypeDAO().updateInfoType(infotype)){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "类型信息修改成功！");
				}
				else {
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "出现错误，类型信息修改失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "必填项不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现错误，类型信息修改失败，请重试！");
			e.printStackTrace();
		}
				
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 根据条件查询类型信息
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 根据条件查询类型信息
	@Log(operationType = Constant.OPERTATION_QUERY, operationDescribe = "根据条件查询类型信息", 
			operationClassPath = "controller.SysTitleManagementController.getInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/getinfotype")
	public String getInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			int pageSize = 10;
			int currentPage = 1;
			if(req.getParameter("limit") != null && !req.getParameter("limit").equals("") 
					&& !req.getParameter("limit").equals("0")){//每页大小
				pageSize = Integer.parseInt(req.getParameter("limit"));
			}
			if (req.getParameter("page") != null && !req.getParameter("page").equals("") 
					&& !req.getParameter("page").equals("0")) {//当前页
				currentPage = Integer.parseInt(req.getParameter("page"));
			}
			List<TFrontInformationType> listsize = DAOFactory.getFrontInformationTypeDAO().getInfoTyepByStr();
			List<TFrontInformationType> list = DAOFactory.getFrontInformationTypeDAO().getInfoTyepByStrPage(currentPage, pageSize);
			if (list != null && list.size() > 0) {
				result.put("code", 0);
				result.put("msg", "查询成功！");
				result.put("count", listsize.size());
				JSONArray jsonArray = JSONArray.fromObject(list);
				result.element("data", jsonArray);
			}
			else {
				result.put("code", 1);
				result.put("msg", "未获取到数据！");
			}
		} catch (Exception e) {
			result.put("code", 1);
			result.put("msg", "出现错误，出现失败，请重试！");
			e.printStackTrace();
		}
				
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 启用一个信息类型
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 启用一个信息类型
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "启用一个信息类型", 
			operationClassPath = "controller.SysTitleManagementController.enableInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/enableinfotype")
	public String enableInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String typeid = req.getParameter("typeid");
			if (typeid != null && !typeid.equals("") && !typeid.equals("0")) {
				if(DAOFactory.getFrontInformationTypeDAO().enable(Integer.parseInt(typeid))){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息类型启用成功！");
				}
				else {
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "出现错误，类型信息启用失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "类型信息编号不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现错误，类型信息启用失败，请重试！");
			e.printStackTrace();
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 停用一个信息类型
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 停用一个信息类型
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "停用一个信息类型", 
			operationClassPath = "controller.SysTitleManagementController.disEnableInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/disenableinfotype")
	public String disEnableInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String typeid = req.getParameter("typeid");
			if (typeid != null && !typeid.equals("") && !typeid.equals("0")) {
				if(DAOFactory.getFrontInformationTypeDAO().disEnable(Integer.parseInt(typeid))){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息类型停用成功！");
				}
				else {
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "出现错误，类型信息停用失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "类型信息编号不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现错误，类型信息停用失败，请重试！");
			e.printStackTrace();
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 删除一个信息类型
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 删除一个信息类型
	@Log(operationType = Constant.OPERTATION_DELETE, operationDescribe = "删除一个信息类型", 
			operationClassPath = "controller.SysTitleManagementController.deleteInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/deleteinfotype")
	public String deleteInfoType(Model model, HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String typeid = req.getParameter("typeid");
			if (typeid != null && !typeid.equals("") && !typeid.equals("0")) {
				if(DAOFactory.getFrontInformationTypeDAO().deleteInfoType(Integer.parseInt(typeid))){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息类型删除成功！");
				}
				else {
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "出现错误，类型信息删除失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "类型信息编号不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现错误，类型信息删除失败，请重试！");
			e.printStackTrace();
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	
	/**
	 * 得到所有的信息类型(不带分页)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 12/14 21:58
	 */
	//TODO 得到所有的信息类型(不带分页)
	@Log(operationType = Constant.OPERTATION_QUERY, operationDescribe = "得到所有的信息类型(不带分页)", 
			operationClassPath = "controller.SysTitleManagementController.getAllInfoType(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息类型管理")
	@RequestMapping(value="/getallinfotype")
	public String getAllInfoType(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		Expression exp=new Expression();
		
		try {
			exp.andEqu("isdelete", true, Boolean.class);
			List<TFrontInformationType> list = DAOFactory.getFrontInformationTypeDAO().getInfoTyepByStr();
			if (list != null && list.size() > 0) {
				result.put("code", 0);
				result.put("msg", "查询成功！");
				result.put("count", list.size());
				JSONArray jsonArray = JSONArray.fromObject(list);
				result.element("data", jsonArray);
			}
			else {
				result.put("code", 1);
				result.put("msg", "未获取到数据！");
			}
		} catch (Exception e) {
			result.put("code", 1);
			result.put("msg", "出现错误，出现失败，请重试！");
			e.printStackTrace();
		}
				
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 将一条信息保存为草稿(待发，后台)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 将一条信息保存为草稿(待发，后台)
	@Log(operationType = Constant.OPERTATION_ADD, operationDescribe = "将一条信息保存为草稿(待发，后台)", 
			operationClassPath = "controller.SysTitleManagementController.addSaveFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/信息添加")	
	@RequestMapping(value="/addsavefrontinformation")
	public String addSaveFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		TFrontInformation info=new TFrontInformation();
		TimeUtil time=new TimeUtil();
		HttpSession session=req.getSession();
		
		try {
			VBackAdminUser backuser=(VBackAdminUser)session.getAttribute("backUser");
			
			String title=req.getParameter("title");
			String content=req.getParameter("content");
			String photoid=req.getParameter("photoid");
			String infotype=req.getParameter("infotype");
			String ishottopic=req.getParameter("ishottopic");
			
			if(title!=null && !title.equals("") && content!=null && !content.equals("")
				&& photoid!=null && !photoid.equals("") && infotype!=null && !infotype.equals("")
				&& ishottopic!=null && !ishottopic.equals("")){
				info.setTitle(title);
				info.setInfocontent(content);
				info.setPhotoid(Integer.parseInt(photoid));
				info.setTypeid(Integer.parseInt(infotype));
				if (ishottopic.equals("0")) {
					info.setIshotarticle(false);
				}
				else {
					info.setIshotarticle(true);
				}
				info.setReadnum(0);
				info.setPraisenum(0);
				info.setCreatetime(time.toTimestamp(new Date()).toString());
				info.setAuthor(backuser.getUserid());
				info.setSendstatus(Constant.WAIT_SENDING);
				boolean row=DAOFactory.getFrontInformationDAO().addFrontInformation(info);
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "保存草稿成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "保存草稿失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "保存草稿失败，请输入必填项！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "保存草稿失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 将一条信息发送(已发，后台)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 将一条信息发送(已发，后台)
	@Log(operationType = Constant.OPERTATION_ADD, operationDescribe = "将一条信息发送(已发，后台)", 
			operationClassPath = "controller.SysTitleManagementController.addSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")	
	@RequestMapping(value="/addsendfrontinformation")
	public String addSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		TFrontInformation info=new TFrontInformation();
		TimeUtil time=new TimeUtil();
		HttpSession session=req.getSession();
		
		try {
			VBackAdminUser backuser=(VBackAdminUser)session.getAttribute("backUser");
			
			String title=req.getParameter("title");
			String content=req.getParameter("content");
			String photoid=req.getParameter("photoid");
			String infotype=req.getParameter("infotype");
			String ishottopic=req.getParameter("ishottopic");
			
			if(title!=null && !title.equals("") && content!=null && !content.equals("")
				&& photoid!=null && !photoid.equals("") && infotype!=null && !infotype.equals("")
				&& ishottopic!=null && !ishottopic.equals("")){
				info.setTitle(title);
				info.setInfocontent(content);
				info.setPhotoid(Integer.parseInt(photoid));
				info.setTypeid(Integer.parseInt(infotype));
				if (ishottopic.equals("0")) {
					info.setIshotarticle(false);
				}
				else {
					info.setIshotarticle(true);
				}
				info.setReadnum(0);
				info.setPraisenum(0);
				info.setCreatetime(time.toTimestamp(new Date()).toString());
				info.setAuthor(backuser.getUserid());
				info.setSendstatus(Constant.ALREADY_SENT);
				boolean row=DAOFactory.getFrontInformationDAO().addFrontInformation(info);
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息发送成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "信息发送失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "信息发送失败，请输入必填项！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "信息发送失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 转发操作(2018-12-15 徐震霖)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 转发操作(2018-12-15 徐震霖)
	@Log(operationType = Constant.OPERTATION_ADD, operationDescribe = "转发信息", 
			operationClassPath = "controller.SysTitleManagementController.addForwardFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/云平台信息推送")
	@RequestMapping(value="/addforwardfrontinformation")
	public String addForwardFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		HttpSession session=req.getSession();
		TimeUtil time = new TimeUtil();
		
		try {
			VBackAdminUser backuser=(VBackAdminUser)session.getAttribute("backUser");
			String infoid = req.getParameter("infoid");
			String photoid = req.getParameter("photoid");
			String ishotarticle = req.getParameter("ishotarticle");
			String infotype = req.getParameter("infotype");
			
			if(infoid != null && !infoid.equals("") && !infoid.equals("0") 
					&& photoid != null && !photoid.equals("") && !photoid.equals("0") 
					&& infotype != null && !infotype.equals("") && !infotype.equals("0") 
					&& ishotarticle != null && !ishotarticle.equals("")){
				VCloudInformation coInformation = DAOFactory.getCloudInformationDAO().
						getVCloudInformationByinfoid(Integer.parseInt(infoid));
				if (coInformation != null) {
					TFrontInformation fInformation = new TFrontInformation();
					fInformation.setAuthor(backuser.getUserid());
					fInformation.setCreatetime(time.toTimestamp(new Date()).toString());
					fInformation.setInfocontent(coInformation.getInfoContent());
					if (ishotarticle.equals("0")) {
						fInformation.setIshotarticle(false);
					}
					else {
						fInformation.setIshotarticle(true);
					}
					fInformation.setOldinfoid(Integer.parseInt(infoid));
					fInformation.setPhotoid(Integer.parseInt(photoid));
					fInformation.setPraisenum(0);
					fInformation.setReadnum(0);
					fInformation.setReleasetime(coInformation.getPublishTime());
					fInformation.setSendstatus(Constant.ALREADY_SENT);
					fInformation.setSource(coInformation.getSchoolid());
					fInformation.setTitle(coInformation.getTopic());
					fInformation.setTypeid(Integer.parseInt(infotype));					
					if(DAOFactory.getFrontInformationDAO().addFrontInformation(fInformation)){
						result.put("code", ResponseJSON.FLAG_SUCC);
						result.put("msg", "信息推送成功！");
					}
					else {
						result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
						result.put("msg", "信息推送失败，请重试！");
					}
				}
				else {
					result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
					result.put("msg", "信息推送失败，请重试！");
				}
			}
			else {
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "必填项不能为空！");
			}
		} catch (Exception e) {
			result.put("code", ResponseJSON.FLAG_FAIL);
			result.put("msg", "出现异常，推送失败，请重试！！");
			e.printStackTrace();
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
		
	}
	
	/**
	 * 根据条件得到待发信息(后台)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 根据条件得到待发信息(后台)
	@Log(operationType = Constant.OPERTATION_QUERY, operationDescribe = "根据条件得到待发信息(后台)", 
			operationClassPath = "controller.SysTitleManagementController.getWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/getwaitsendfrontinfo")
	public String getWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		Expression exp=new Expression();
		
		try {
			String title=req.getParameter("title");
			String currentPage=req.getParameter("page");
			String pageSize=req.getParameter("limit");
			if(currentPage!=null && !currentPage.equals("") && pageSize!=null && !pageSize.equals("")){
				if(title!=null && !title.equals("")){
					exp.andLike("title", title, String.class);
				}
				exp.andEqu("sendstatus", Constant.WAIT_SENDING, Integer.class);
				exp.orderByDesc("createtime");
				List<VFrontInformation> listsize=DAOFactory.getFrontInformationDAO().
						getFrontInformationList(exp.toString());
				List<VFrontInformation> list=DAOFactory.getFrontInformationDAO().getFrontInformationList
						(exp.toString(), Integer.parseInt(currentPage), Integer.parseInt(pageSize));
				if(list!=null && list.size()>0 && listsize.size()>0 && listsize!=null){
					result.put("code", 0);
					result.put("msg", "查询成功！");
					result.put("count", list.size());
					JSONArray jsonArray = JSONArray.fromObject(list);
					result.element("data", jsonArray);
				}else{
					result.put("code", 1);
					result.put("msg", "无查询结果！");
				}
			}else{
				result.put("code", 1);
				result.put("msg", "无查询结果！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", 2);
			result.put("msg", "无查询结果！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}

	/**
	 * 发送一条待发信息(后台)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 发送一条待发信息(后台)
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "发送一条待发信息(后台)", 
			operationClassPath = "controller.SysTitleManagementController.sendWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/sendwaitsendfrontinfo")
	public String sendWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String infoid=req.getParameter("infoid");
			if(infoid!=null && !infoid.equals("")){
				TFrontInformation info=DAOFactory.getFrontInformationDAO().
						getTFrontInformation(Integer.parseInt(infoid));
				info.setSendstatus(Constant.ALREADY_SENT);
				boolean row=DAOFactory.getFrontInformationDAO().updateFrontInformation(info);
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "发送成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "发送失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "发送失败！");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "发送失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 删除一条待发信息(后台)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 删除一条待发信息(后台)
	@Log(operationType = Constant.OPERTATION_DELETE, operationDescribe = "删除一条待发信息(后台)", 
			operationClassPath = "controller.SysTitleManagementController.delWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/delwaitsendfrontinfo")
	public String delWaitSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String infoid=req.getParameter("infoid");
			if(infoid!=null && !infoid.equals("")){
				boolean row=DAOFactory.getFrontInformationDAO().
						deleteFrontInformation(Integer.parseInt(infoid));
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "删除成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "删除失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "删除失败！");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "删除失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 根据条件得到已发信息(后台，已发)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 * @author djf
	 * @since 2018/12/15
	 */
	//TODO 根据条件得到待发信息(后台)
	@Log(operationType = Constant.OPERTATION_QUERY, operationDescribe = "根据条件得到待发信息(后台)", 
			operationClassPath = "controller.SysTitleManagementController.getIsSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/getissendfrontinfo")
	public String getIsSendFrontInfo(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		Expression exp=new Expression();
		
		try {
			String typeid=req.getParameter("typeid");
			String title=req.getParameter("title");
			String currentPage=req.getParameter("page");
			String pageSize=req.getParameter("limit");
			if(currentPage!=null && !currentPage.equals("") && pageSize!=null && !pageSize.equals("")){
				if(typeid!=null && !typeid.equals("")){
					exp.andEqu("typeid", typeid, String.class);
				}
				if(title!=null && !title.equals("")){
					exp.andLike("title", title, String.class);
				}
				exp.andEqu("sendstatus", Constant.ALREADY_SENT, Integer.class);
				exp.orderByDesc("createtime");
				List<VFrontInformation> listsize=DAOFactory.getFrontInformationDAO().
						getFrontInformationList(exp.toString());
				List<VFrontInformation> list=DAOFactory.getFrontInformationDAO().getFrontInformationList
						(exp.toString(), Integer.parseInt(currentPage), Integer.parseInt(pageSize));
				if(list!=null && list.size()>0 && listsize.size()>0 && listsize!=null){
					result.put("code", 0);
					result.put("msg", "查询成功！");
					result.put("count", listsize.size());
					JSONArray jsonArray = JSONArray.fromObject(list);
					result.element("data", jsonArray);
				}else{
					result.put("code", 1);
					result.put("msg", "无查询结果！");
				}
			}else{
				result.put("code", 1);
				result.put("msg", "无查询结果！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", 2);
			result.put("msg", "无查询结果！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 保存一条待发信息(后台，待发)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 保存一条待发信息(后台，待发)
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "保存一条待发信息(后台，待发)", 
			operationClassPath = "controller.SysTitleManagementController.saveWaitSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/savewaitsendfrontinfo")
	public String saveWaitSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String infoid=req.getParameter("infoid");
			String title=req.getParameter("title");
			String content=req.getParameter("content");
			String photoid=req.getParameter("photoid");
			String infotype=req.getParameter("infotype");
			String ishottopic=req.getParameter("ishottopic");
			
			if(infoid!=null && !infoid.equals("") && title!=null && !title.equals("") && content!=null && !content.equals("")
				&& photoid!=null && !photoid.equals("") && infotype!=null && !infotype.equals("")
				&& ishottopic!=null && !ishottopic.equals("")){
				
				TFrontInformation info=DAOFactory.getFrontInformationDAO().
						getTFrontInformation(Integer.parseInt(infoid));
				
				info.setTitle(title);
				info.setInfocontent(content);
				info.setPhotoid(Integer.parseInt(photoid));
				info.setTypeid(Integer.parseInt(infotype));
				if (ishottopic.equals("0")) {
					info.setIshotarticle(false);
				}
				else {
					info.setIshotarticle(true);
				}
				boolean row=DAOFactory.getFrontInformationDAO().updateFrontInformation(info);
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息修改成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "信息修改失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "信息修改失败，请输入必填项！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "信息修改失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
	/**
	 * 保存发送一条待发信息(后台，保存，发送)
	 * @param model
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	//TODO 保存发送一条待发信息(后台，保存，发送)
	@Log(operationType = Constant.OPERTATION_UPDATE, operationDescribe = "保存发送一条待发信息(后台，保存，发送)", 
			operationClassPath = "controller.SysTitleManagementController.sendSaveWaitSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp)", 
			operationMenu = "网站信息管理/待发信息")
	@RequestMapping(value="/sendsavewaitsendfrontinfo")
	public String sendSaveWaitSendFrontInformation(Model model, HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
		
		JSONObject result = new JSONObject();
		
		try {
			String infoid=req.getParameter("infoid");
			String title=req.getParameter("title");
			String content=req.getParameter("content");
			String photoid=req.getParameter("photoid");
			String infotype=req.getParameter("infotype");
			String ishottopic=req.getParameter("ishottopic");
			
			if(infoid!=null && !infoid.equals("") && title!=null && !title.equals("") && content!=null && !content.equals("")
				&& photoid!=null && !photoid.equals("") && infotype!=null && !infotype.equals("")
				&& ishottopic!=null && !ishottopic.equals("")){
				
				TFrontInformation info=DAOFactory.getFrontInformationDAO().
						getTFrontInformation(Integer.parseInt(infoid));
				
				info.setTitle(title);
				info.setInfocontent(content);
				info.setPhotoid(Integer.parseInt(photoid));
				info.setTypeid(Integer.parseInt(infotype));
				if (ishottopic.equals("0")) {
					info.setIshotarticle(false);
				}
				else {
					info.setIshotarticle(true);
				}
				info.setSendstatus(Constant.ALREADY_SENT);
				boolean row=DAOFactory.getFrontInformationDAO().updateFrontInformation(info);
				if(row){
					result.put("code", ResponseJSON.FLAG_SUCC);
					result.put("msg", "信息发送成功！");
				}else{
					result.put("code", ResponseJSON.FLAG_FAIL);
					result.put("msg", "信息发送失败！");
				}
			}else{
				result.put("code", ResponseJSON.FLAG_FAIL);
				result.put("msg", "信息发送失败，请输入必填项！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", ResponseJSON.FLAG_UNKNOWN_ERORR);
			result.put("msg", "信息发送失败！");
		}
		
		PrintWriter out = resp.getWriter();
		out.println(result);
		return null;
	}
	
}
